<%@ page import="java.util.HashMap,common.CommonUtil,java.util.*,common.*,db.QueryManager" contentType="text/html; charset=utf-8" %>
<%
UserSession userSession = (UserSession)session.getAttribute("user"); 

//String login_id = null;
String user_id = null;
String level = null;

if(userSession!= null){
	//login_id = userSession.getLogin_id();
	user_id = userSession.getUser_id();
	level = userSession.getAdmin_level();
}

//페이징 처리 Start
String line_number	= CommonUtil.nvl(request.getParameter("line_number"));
String curr_page = CommonUtil.nvl(request.getParameter("curr_page"));
String total_count = CommonUtil.nvl(request.getParameter("total_count"));
String s_rating_state = CommonUtil.nvl(request.getParameter("rating_state"));
String search_combo = CommonUtil.nvl(request.getParameter("search_combo"));
String keyword = CommonUtil.nvl(request.getParameter("keyword"));

String start_date	= CommonUtil.nvl(request.getParameter("start_date"),""); 
String end_date	= CommonUtil.nvl(request.getParameter("end_date"),"");
//페이징 처리 End

String BASE_PREP_GRADE = QueryManager.getQuery("prep.grade");
String[] prep_grade_arr = BASE_PREP_GRADE.split("-");
int prep_grade_cnt = prep_grade_arr.length;

HashMap listMap=(HashMap)request.getAttribute("list_map");
HashMap map = null;
HashMap map1 = null;
HashMap map2 = null;
HashMap map3 = null;
HashMap map4 = null;
HashMap map5 = null;
HashMap map6 = null;

ArrayList list=null;
ArrayList list1=null;
ArrayList list2=null;
ArrayList list3=null;
ArrayList list4=null;
ArrayList list5=null;
ArrayList list6=null;

if (listMap!=null && listMap.size() >0){
	list=(ArrayList)listMap.get("mainContent");
	
	list1=(ArrayList)listMap.get("mainContent1");
	
	list2=(ArrayList)listMap.get("mainContent2");
	
	list3=(ArrayList)listMap.get("mainContent3");
	
	list4=(ArrayList)listMap.get("mainContent4");
	list5=(ArrayList)listMap.get("mainContent5");
	list6=(ArrayList)listMap.get("mainContent6");
}

String member_test_code 		= "";
String member_id 		= "";
String test_state 		= "";
String reg_dt 	= "";
String login_id_map 		= "";
String login_name 	= "";
String email	= "";
String cell_no	= "";

String rater_id 	= "";
String rating_state 		= "";
String rating_start_time 	= "";
String rating_close_time	= "";
String rating_reg_dt	= "";
String rater_name 	= "";

String rating_grade = "";
String rating_cont = "";

String cd = "";
String cd_nm = "";

String rating_grade_cnt = "";

String sign_code="";
String link_id="";

String grade_his = "";

if(list != null){
	if(list.size() > 0){
		
		login_id_map = CommonUtil.nvl(Crypto.DecodeBySType((String)((HashMap)list.get(0)).get("login_id")));
		
		member_test_code = CommonUtil.nvl((String)((HashMap)list.get(0)).get("member_test_code"));		
		member_id = CommonUtil.nvl((String)((HashMap)list.get(0)).get("member_id"));
		test_state = CommonUtil.nvl((String)((HashMap)list.get(0)).get("test_state"));
		reg_dt = CommonUtil.nvl((String)((HashMap)list.get(0)).get("reg_dt"));
		login_name = CommonUtil.nvl((String)((HashMap)list.get(0)).get("login_name"));
		
		email = CommonUtil.nvl((String)((HashMap)list.get(0)).get("email"));
		cell_no = CommonUtil.nvl((String)((HashMap)list.get(0)).get("cell_no"));
		rater_id = CommonUtil.nvl((String)((HashMap)list.get(0)).get("rater_id"));
		rating_state = CommonUtil.nvl((String)((HashMap)list.get(0)).get("rating_state"));
		rating_start_time = CommonUtil.nvl((String)((HashMap)list.get(0)).get("rating_start_time"));
		rating_close_time = CommonUtil.nvl((String)((HashMap)list.get(0)).get("rating_close_time"));
		rating_reg_dt = CommonUtil.nvl((String)((HashMap)list.get(0)).get("rating_reg_dt"));
		rater_name = CommonUtil.nvl((String)((HashMap)list.get(0)).get("rater_name"));
		
		rating_grade = CommonUtil.nvl((String)((HashMap)list.get(0)).get("rating_grade"));
		rating_cont = CommonUtil.nvl((String)((HashMap)list.get(0)).get("rating_cont"));
		
		sign_code = CommonUtil.nvl((String)((HashMap)list.get(0)).get("sign_code"));
		link_id = CommonUtil.nvl((String)((HashMap)list.get(0)).get("link_id"));
		
		grade_his = CommonUtil.nvl((String)((HashMap)list.get(0)).get("grade_his"));
	}
}

if(!rater_id.equals(user_id) && level.equals("4")){
	out.println("<script>alert('Non authority.');history.back();</script>");
}
%>
<jsp:include page="/jsp/common/header.jsp"></jsp:include>
<script language='javascript' src="/js/ajaxutil.js"></script>

<script>

//xml 요청
function getXMLHTTPRequest() {
try {
req = new XMLHttpRequest();
} catch(err1) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (err2) {
  try {
  req = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (err3) {
    req = false;
  } 
} 
}
return req;
}


function get_rater_give_request(mc,ri,si,li){

var http = getXMLHTTPRequest();
var myurl = '/speaking.pb?gubun=prep&cmd=rater_give&member_test_code='+mc+'&rater_id='+ri+'&pay_code='+si+'&link_id='+li+'&test_state=2&rating_state=1';
myRand = parseInt(Math.random()*999999999999999);
var modurl = myurl+"&rand="+myRand;  
http.open("get", modurl, false);
//http.onreadystatechange = useHttpResponse;
http.send(null);
if (http.readyState == 4) {
  return trim(http.responseText);
}else{
 return "";
}
} 	

function trim(str){
	str = str.replace(/(^\s*)|(\s*$)/g,"");
	return str;
}

function get_rater_chk(mc,ri,si,li){
	var frm = document.mainform;
	
	if(!confirm('Allocate?')){
		return;
	}
	
	if(ri == ''){
		alert('Rater Select');		
	}
	var rater_chk = get_rater_give_request(mc,ri,si,li);
	
	alert('Allocate.');	
	go_select()	;	
	/*
	if(trim(rater_chk)=='OK'){
		
		alert('Allocate.');
		
		go_select()	;		
		
	}else{
		alert('problem');
	}
	*/
}

function go_select(){
	var frm = document.mainform;
	
	frm.cmd.value='preptest_select';
	frm.action = '/speaking.pb';
	frm.target= '_self';              
	frm.submit();	
}

function go_rerating(){
	var frm = document.mainform;
	if(confirm('UnRating ?')){
		
		unrating_comment.style.display = "block";
		if(frm.rerating_reason.value == ''){
			alert('UnRating reason insert');
			frm.rerating_reason.focus();
			return;
		}
		
		frm.cmd.value='preptest_rerating';
		frm.action = '/speaking.pb';
		frm.target= 'hidden_frm';              
		frm.submit();	
	}
}

function go_input(){
	var frm = document.mainform;	
	
		
	var ch_garde_cnt = 0;
	for(var i=0;i<frm.rating_grade.length;i++){
		if(frm.rating_grade[i].checked == true) ch_garde_cnt++;
	}
	
	if(ch_garde_cnt==0){
		alert('Grade Select.');
		frm.rating_grade[0].focus();
		return;
	}
	
	/*
	if(frm.rating_cont.value==''){
		alert('Comment Insert');
		frm.rating_cont.focus();
		return;
	}
	*/
	//alert(frm.rater_comment_cnt.value);
	var cnt = frm.rater_comment_cnt.value;
	var ch_comment_cnt = 0;
	if(cnt > 1){
		for(var i=0;i<cnt;i++){			
			if(frm.rater_comment_sel[i].value == '') ch_comment_cnt++;
		}
		
		if(ch_comment_cnt>0){
			alert('Comment Select.');	
			frm.rater_comment_sel[0].focus();
			return;
		}
	}else{
		if(frm.rater_comment_sel.value==''){
			alert('Comment Select.');
			frm.rater_comment_sel.focus();
			return;
		}
	}
	
	
	frm.action = '/speaking.pb?cmd=preptest_modify';
	frm.target= 'hidden_frm';              
	frm.submit();
	
}


function go_preptest(){
	
	var frm = document.moveform;	
	frm.cmd.value='preptest_main';
	frm.action = '/speaking.pb';
	frm.target= '_self';              
	frm.submit();
	
}

function Mplayer_Player_Base(){
	var m_w, m_h;
	var tag;
	m_w = 0;
	m_h = 0;
	tag = "<OBJECT ID='MediaPlayer' Name='MediaPlayer' classid='clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701' standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject ' bgcolor='DarkBlue' width='"+ m_w +"' Height='"+ m_h +"' VIEWASTEXT style='FILTER:gray()'>"
                + "<PARAM NAME='AutoStart' VALUE='1'>"
                + "<PARAM NAME='AutoSize' VALUE='1'>"
                + "<PARAM NAME='AnimationAtStart' VALUE='0'>"
                + "<PARAM NAME='DisplayMode' VALUE='3'>"
                + "<PARAM NAME='Enabled' VALUE='1'>"
                + "<PARAM NAME='ShowControls' VALUE='1'>"
                + "<PARAM NAME='ShowAudioControls' VALUE='1'>"
                + "<PARAM NAME='ShowDisplay' VALUE='0'>"
                + "<PARAM NAME='ShowGotoBar' VALUE='0'>"
                + "<PARAM NAME='ShowPositionControls' VALUE='1'>"
                + "<PARAM NAME='ShowStatusBar' VALUE='0'>"
                + "<PARAM NAME='Volume' VALUE='50'>"
                + "<PARAM NAME='ShowCaptioning' VALUE='0'>"
                + "<PARAM NAME='TransparentAtStart' value='1'>"				
				+ "</OBJECT>";

	  document.write(tag);	 
	  
}
function Mplayer_Player(f){
MediaPlayer.Filename = f;
MediaPlayer.play();
}

function Mplayer_Player_stop(){
	MediaPlayer.stop();
}


function record_listen(record_file_url){
	//var test_url = "/speaking_test.pb?cmd=download2&file_id="+record_file_url+"&file_name="+record_file_url+"&file_folder=preptest";
	var test_url = "/uploads/preptest/"+record_file_url;
	Mplayer_Player(test_url);	
}

function record_stop(){
	Mplayer_Player_stop();
}

</script>

<SCRIPT FOR="MediaPlayer" EVENT="EndOfStream(mState)" LANGUAGE="JavaScript"> 
if (mState == 0)
{
	if(MediaPlayer.PlayCount==1)
	{
		alert("Play Stop");
	}
}
</SCRIPT>

<jsp:include page="/jsp/common/top.jsp"></jsp:include>
<jsp:include page="/jsp/common/submenu.jsp"><jsp:param name="submenu_id" value="preptest_main" /><jsp:param name="submenu_idx" value="1" /></jsp:include>

<form name="mainform"  method="post" action = "/speaking.pb" >
	<div id="bodyContainer">
        <div id="contents">
          <jsp:include page="/jsp/common/submenu_list.jsp"><jsp:param name="submenu_id" value="preptest_main" /><jsp:param name="submenu_idx" value="2" /></jsp:include>
          
          
          <div class="boxContainer">
            <dl title="Status of Tests and Ratings">
              <dt>Status of Tests and Ratings</dt>
            </dl>
            <table class="setupTb">
              <tr>
                <th>ID</th>
                <td><%=login_id_map %></td>
              </tr>
              <tr>
                <th>Name</th>
                <td><%=login_name %></td>
              </tr>
              <tr>
                <th>E-mail</th>
                <td><label for="textfield"></label>
                  <%=email %></td>
              </tr>
              <tr>
                <th>Phone Number</th>
                <td><%=cell_no %></td>
              </tr>
              <tr>
                <th>Date of Test</th>
                <td><%=reg_dt %></td>
              </tr>
              <tr>
                <th>Rater / Status</th>
                <td>
                <%if(level.equals("1") || level.equals("2")){ %>
              	<%if(!rater_id.equals("") && !rating_state.equals("Holding") || rating_state.equals("2")){ %>
                <%=rater_name %>
                <%}else{ %>
                <select name="rater" id="rater" style="width:100px" onchange="get_rater_chk('<%=member_test_code %>',this.value,'<%=sign_code %>','<%=link_id %>')">
                  <option value=''>Rater Select</option>
                <%
                if (list2!=null && list2.size()> 0) {
			    	for(int k=0; k<list2.size(); k++){
				      map2=(HashMap)list2.get(k);
				      cd = CommonUtil.nvl((String)map2.get("cd"));
				      cd_nm = CommonUtil.nvl((String)map2.get("cd_nm"));
				
				%>		        
                  <option value="<%=cd %>" <%=(rater_id.equals(cd))?"selected":"" %>><%=cd_nm %></option>
                <%
			    	}
                }
                %>  
                </select> <!-- <a href="#"><img src="img/btn_assign2.gif" alt="할당" border="0" align="middle" /></a> -->
                <%} %>
                <%}else{ %>
                <%=rater_name %>
                <%} %>
                
                &nbsp;&nbsp;/&nbsp;&nbsp;
                <%if(rating_state.equals("1")){ %>
                <img src="img/btn_progress.gif" alt="진행중" border="0" align="absmiddle" />
                <%}else if (rating_state.equals("2")){%>
                <img src="img/btn_complete.gif" alt="완료" border="0" align="absmiddle"/>
                <%}else if (rating_state.equals("9")){%>
                	재시험
                <%}else if (rating_state.equals("Holding")){%>
                <img src="img/btn_holding.gif" alt="홀딩" border="0" align="absmiddle"/>
                <%}else{ %>
                <img src='img/btn_ready.gif' alt='레디' border="0" align="absmiddle"/>
                <%} %>
                
                </td>
              </tr>  
              <tr>
                <th>Record Listen</th>
                <td>
                <%
                String grade="";
                String exam_num="";
                String member_test_answer_id="";
                String member_test_answer_nm="";
                String member_test_record_file_path="";
                String explane_cont="";
                String level_name="";
                for(int j=0 ; list1!=null && list1.size() > j ; j++){ 
        			map1 = (HashMap)list1.get(j);
        			grade = CommonUtil.nvl((String)map1.get("grade"));
        			exam_num = CommonUtil.nvl((String)map1.get("exam_num"));
        			member_test_answer_id = CommonUtil.nvl((String)map1.get("member_test_answer_id"));
        			member_test_answer_nm = CommonUtil.nvl((String)map1.get("member_test_answer_nm"));
        			member_test_record_file_path = CommonUtil.nvl((String)map1.get("member_test_record_file_path"));
        			explane_cont = CommonUtil.nvl((String)map1.get("explane_cont"));
        			level_name = CommonUtil.nvl((String)map1.get("level_name"));
        			
        			if(!grade_his.equals("")) grade = grade_his;
                %>
                <%=(j==0)?"<b>Test Style : "+grade+" </b> <br><br>":"" %>
                Q<%=exam_num %> : 
                <a href="#q<%=exam_num %>" onclick="record_listen('<%=member_test_record_file_path%>/<%=member_test_answer_id%>')" name="q<%=exam_num %>">
                <img src="img/btn_listen2.gif" alt="start" align="middle"/></a> 
                <a href="#q<%=exam_num %>" onclick="record_stop()" >
                <img src="img/btn_listen_end.gif" alt="stop"  align="middle"/></a>
                <!--  <br> level : <%=level_name %>  -->
                <br> Content : <%=explane_cont %>
                <br />
                <br />
               <%} %>
               </td>
              </tr>
              <tr>
                <th>Grade History</th>
                <td>
                <br>
                <table >
                	<tr>
                	<%
	                for(int i=0;i<prep_grade_cnt;i++){
	                %>
                	<td><b><%=prep_grade_arr[i] %></b></td> 
					<%} %>
                	</tr>
                	<tr>
	                <%
	                for(int i=0;i<prep_grade_cnt;i++){
	                	rating_grade_cnt = "";
	                
		                if (list3!=null && list3.size()> 0) {
					    	for(int l=0; l<list3.size(); l++){
						      map3=(HashMap)list3.get(l);
						      if(prep_grade_arr[i].equals(CommonUtil.nvl((String)map3.get("rating_grade")))){
						    	  rating_grade_cnt =CommonUtil.nvl((String)map3.get("rating_grade_cnt"));
						      }
					    	}
		                }
	                %> 
	                <td><%=(!rating_grade_cnt.equals(""))?rating_grade_cnt:"0" %></td>
	                <%	
	                }
	                %>
	                </tr>
                </table>
                <br>
                </td>
              </tr>
              <tr>
                <th>Grade</th>
                <td>
                	<%
	                for(int i=0;i<prep_grade_cnt;i++){
	                %>
                	<input type="radio" name="rating_grade" id="rating_grade" value="<%=prep_grade_arr[i] %>" <%=(rating_grade.equals(prep_grade_arr[i])?"checked":"") %>/>
                  	<span class="boldText"><%=prep_grade_arr[i] %> </span>
					<%} %>          
                </td>
              </tr>
              <tr>
                <th>Comment</th>
                <td>
                
                <table >                	
<%
String rrg_code = "";
String rrg_eng_name = "";
String rrg_kor_name = "";
String eng_yn = "";

String rrg_code_sml = "";
String eng_yn_sml = "";
String rsml_code = "";
String rsml_eng_name = "";
String rsml_kor_name = "";

String select_comment_chk = "";

for(int r=0 ; list4!=null && list4.size() > r; r++){ 
	map4 = (HashMap)list4.get(r);
	rrg_code = CommonUtil.nvl((String)map4.get("rrg_code"));
	rrg_eng_name = CommonUtil.nvl((String)map4.get("rrg_eng_name"));
	rrg_kor_name = CommonUtil.nvl((String)map4.get("rrg_kor_name"));
	eng_yn = CommonUtil.nvl((String)map4.get("eng_yn"));
%>                
                <tr>
                <td>
                	<b><%= rrg_eng_name%> : </b>
                </td>	
                <td>
                <select name="rater_comment_sel">
                <option value="">select</option>
<%
	for(int s=0 ; list5!=null && list5.size() > s; s++){ 
		map5 = (HashMap)list5.get(s);
		rrg_code_sml = CommonUtil.nvl((String)map5.get("rrg_code"));
		eng_yn_sml = CommonUtil.nvl((String)map5.get("eng_yn"));
		rsml_code = CommonUtil.nvl((String)map5.get("rsml_code"));
		rsml_eng_name = CommonUtil.nvl((String)map5.get("rsml_eng_name"));
		rsml_kor_name = CommonUtil.nvl((String)map5.get("rsml_kor_name"));
		
		if(rrg_code.equals(rrg_code_sml)){
			select_comment_chk = "";
			
			for(int sc=0 ; list6!=null && list6.size() > sc; sc++){ 
				map6 = (HashMap)list6.get(sc);
				
				//System.out.println("rsml_code=======>"+rsml_code+" rsml_code====>"+CommonUtil.nvl((String)map6.get("rsml_code")));
				//System.out.println("rrg_code_sml=======>"+rrg_code_sml+" rrg_code====>"+CommonUtil.nvl((String)map6.get("rrg_code")));
				
				if(rsml_code.equals(CommonUtil.nvl((String)map6.get("rsml_code"))) && rrg_code_sml.equals(CommonUtil.nvl((String)map6.get("rrg_code"))) ){
					select_comment_chk = "selected";
				}
			}
%>
				<option value="<%=rrg_code_sml %>-<%=rsml_code %>" <%=select_comment_chk %>><%=rsml_eng_name %></option>
<%
		}
	} 
%>                
                </select>
                </td>
                </tr>
<%} %>                
                <!--  
                <tr>
                <td colspan=2>
                <textarea name="rating_cont" rows="5" id="rating_cont" style="width:450px"><%=rating_cont %></textarea>
                </td>
                </tr>
                -->
                </table>
                </td>
              </tr>
              <tr style="display:none" id="unrating_comment">
                <th>UnRating Reason</th>
                <td><textarea name="rerating_reason" rows="5" id="rerating_reason" style="width:450px"></textarea></td>
              </tr>
            </table>
            <p><%if (!rating_state.equals("2")){ %><a href="#" onclick="go_input()"><img src="img/btn_rating.gif" alt="rating"  /></a> <a href="#" onclick="go_rerating()"><img src="img/btn_unrating.gif" alt="unrating"  /></a><%}else{ %> <a href="#" onclick="go_input()"><img src="img/btn_rating.gif" alt="rating"  /></a><%} %> <a href="#" onclick="go_preptest()"><img src="img/btn_list_eng.gif" alt="목록" width="49" height="20" /></a> </p>
            
          </div>
          
        </div>
      </div>


<input type="hidden" name="cmd" value="">
<input type="hidden" name="user_id" value="<%=user_id %>">
<input type="hidden" name="member_id" value="<%=member_id %>">
<input type="hidden" name="member_test_code" value="<%=member_test_code %>">
<input type="hidden" name="rater_comment_cnt" value="<%=list4.size() %>">

<input type="hidden" name="sign_code" value="<%=sign_code %>">
<input type="hidden" name="link_id" value="<%=link_id %>">

</form>

<form name="moveform"  method="post" action = "/speaking.pb" >
<input type="hidden" name="cmd" value="">
<input type="hidden" name="user_id" value="<%=user_id %>">

<input type="hidden" name="line_number" value="<%=line_number%>">
<input type="hidden" name="curr_page" value="<%=curr_page%>">
<input type="hidden" name="total_count" value="<%=total_count%>">

<input type="hidden" name="rating_state" value="<%=s_rating_state%>">
<input type="hidden" name="search_combo" value="<%=search_combo%>">
<input type="hidden" name="keyword" value="<%=keyword%>">

<input type="hidden" name="start_date" value="<%=start_date%>">
<input type="hidden" name="end_date" value="<%=end_date%>">
</form>

<iframe name='hidden_frm'  width='0' height='0' SCROLLING='AUTO' frameborder='0'></iframe>

<script>
Mplayer_Player_Base();
</script>
<jsp:include page="/jsp/common/footer.jsp"></jsp:include>
<jsp:include page="/jsp/common/bottom.jsp"></jsp:include>
